package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.goods.Brand;
import com.qingcheng.service.goods.BrandService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Reference
    private BrandService brandService;

    //查询所有
    @RequestMapping("/findAll")
    public List<Brand> findAll() {
        return brandService.findAll();
    }


    //分页查询,只能用get方式请求
    @GetMapping("/findPage")
    public PageResult<Brand> findPage(int page,int size) {
        return brandService.findPage(page,size);
    }

    //条件查询
    @PostMapping("/findList")
    public List<Brand> findList(@RequestBody Map searchMap) {
        return brandService.findList(searchMap);
    }

    //分页条件查询
    @PostMapping("/findListByPage")
    public List<Brand> findListByPage(int page,int size,@RequestBody Map searchMap) {
        return brandService.findListByPage(page,size,searchMap);
    }

    //id查询
    @GetMapping("/findByid")
    public Brand findById(Integer id) {
        return brandService.findById(id);
    }

    //新增
    @PostMapping("/add")
    public Result add(@RequestBody Brand brand) {
        int i = 1/0;
        brandService.add(brand);
        return new Result();
    }

    //修改
    @PostMapping("/update")
    public Result update(@RequestBody Brand brand) {
        brandService.update(brand);
        return new Result();
    }

    //删除
    @GetMapping("/delete")
    public Result del(Integer id) {
        brandService.delete(id);
        return new Result();
    }

}
